Page({
  data: {
    team_members: [
      { id: 1, name: '童万登', username: 'tongwandeng', head_pic: "登"},
      { id: 2, name: '倪忠卫', username: 'nizhongwei', head_pic: "卫"},
      { id: 3, name: '王培栋', username: 'wangpeidong', head_pic: "栋"},
      { id: 4, name: '李邵瑜', username: 'lishaoyu', head_pic: "瑜"},
      { id: 5, name: '小胖', username: 'xiaopang', head_pic: "胖"},
      { id: 6, name: '沈杰', username: 'shenjie', head_pic: "杰"}
    ]
  },
  onLoad: function (options){
    // 接受页面传值
    this.setData({
      taskname: options.taskname
    })
    console.log(this.data.taskname)
    // 给头像分配颜色
    var colorArr = ['#5D9050', '#5E8DA3', '#2156B5', '#289787', '#CD241A', '#3CA1D2','#589358', '#5E8DA3', '#367F64', '#D39E53', '#CB374C', '#7F6F76', '#06A3A3', '#06A3A3', '#3F1850'];
    for (var i = 0; i < this.data.team_members.length; i++) {
      var item = 'team_members[' + i + '].background_pic';
        if(colorArr.length > this.data.team_members.length){
          this.setData({
            [item]: colorArr[i]
          })
        }else{
          this.setData({
            [item]: colorArr[Math.floor(Math.random() * colorArr.length)]
          })
        }
    }
  },
  // 确定转单给他人
  confirmTurn:function(e){
    wx.showModal({
      title: '提示',
      content: "确定要把任务 "+ this.data.taskname +" 转给 " + e.currentTarget.id  +" 么？",
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  },
  goBack: function () {
    wx.navigateBack({ changed: true });
  }
})